var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(f, d, c) {
    if (status == 0 && f == 0) {
        cm.dispose();
        return
    }(f == 1) ? status++ : status--;
    selectionLog[status] = c;
    var b = -1;
    if (status <= b++) {
        cm.dispose()
    } else {
        if (status === b++) {
            if (cm.isQuestActive(41315)) {
                cm.sendNormalTalk("(将#r#t4033866##k放入糖果机器开始启动)", 0, 2470009, false, true)
            } else {
                cm.sendNormalTalk("内有五彩斑斓美味糖果的糖果机器。", 0, 2470009, false, false);
                cm.dispose()
            }
        } else {
            if (status === b++) {
                var a = [4033868, 4033869, 4033870, 4033871];
                var e = a[cm.rand(0, a.length)];
                cm.sendNormalTalk("(从糖果机器中获得了#r#t" + e + "##k)", 0, 2470009, true, true);
                cm.gainItem(4033866, -1);
                cm.gainItem(e, 1);
                cm.dispose()
            }
        }
    }
};